package com.jadeen.service.impl;


import com.jadeen.common.domain.AjaxResult;
import com.jadeen.entity.domain.Resource;
import com.jadeen.mapper.IndexMapper;
import com.jadeen.mapper.ResourceMapper;
import com.jadeen.service.IIndexService;
import com.jadeen.service.IResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 标签Service业务层处理
 * 
 * @author jadeen
 * @date 2025-08-08
 */
@Service
public class IndexServiceImpl implements IIndexService
{
    @Autowired
    private IndexMapper indexMapper;
    @Autowired
    private ResourceMapper resourceMapper;
    @Autowired
    private IResourceService resourceService;

    @Override
    public AjaxResult categoryResource() {
        List<Map<String, Object>> categoryResource = resourceMapper.getCategoryResource();
        // 创建两个列表分别存储 categoryName 和 count
        List<String> categoryNames = new ArrayList<>();
        List<Integer> counts = new ArrayList<>();
        // 遍历数据，分别提取 categoryName 和 count
        categoryResource.forEach(item -> {
            categoryNames.add((String) item.get("categoryName"));
            counts.add(((Long) item.get("count")).intValue());
        });
        // 创建结果 Map
        HashMap<String, Object> result = new HashMap<>();
        result.put("categoryNames", categoryNames);
        result.put("counts", counts);

        return AjaxResult.success(result);
    }

//    @Override
//    public AjaxResult dayGrowth() {
//        resourceMapper.dayGrowth();
//        return null;
//    }

    @Override
    public AjaxResult downLoadAndView() {
        List<Resource> resources = resourceService.selectDownLoadAndView();
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        ArrayList<Object> resourceNameList = new ArrayList<>();
        ArrayList<Object> downloadCountList = new ArrayList<>();
        ArrayList<Object> viewCountList = new ArrayList<>();
        resources.forEach(item -> {
            resourceNameList.add(item.getTitle());
            downloadCountList.add(item.getDownloadCount());
            viewCountList.add(item.getViewCount());
        });
        stringObjectHashMap.put("resourceName",resourceNameList);
        stringObjectHashMap.put("downloadCount",downloadCountList);
        stringObjectHashMap.put("viewCount",viewCountList);
        return AjaxResult.success(stringObjectHashMap);
    }
}
